# --**coding:utf-8**--

from drive import Driver
import utils

class SelectElement:

    def __init__(self, element_list:list, d:Driver):
        self.d = d
        self.element_list = element_list
        self.click_list = []
        self.filter_list = []
        self.last_operator_list = []
        self.u = utils
        self.folder_path = foldef_path

    def _getKeys(self,item:dict):
        return item.keys()

    def getSelectList(self):
        for item in self.element_list:
            if isinstance(item:dict):
                keys = self._getKeys(item)
                if '@clickable' in keys and item.get('@clickable') == True:
                    self.click_list.append(item)
            else:
                return


    def run(self,page_activity_name):
        for item in self.click_list:
            keys = self._getKeys(item)
            if '@text' in keys:
                x,y = self.d.getElementBounds(item)
                bounds_md5 = self.u.getMd5(f"{x}+{y}")
                self.d.clickElementByBounds(bounds_X=x,bounds_y=y,folder_path=self.foler_path,bounds_md5=bounds_md5,page_actrivity_name=page_activity_name)
        return True